/*
 * Copyright (c) 2017.
 */
package com.whty.ssm.db02.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements com.whty.ssm.db02.service.AccountService {
	
	@Autowired
	private com.whty.ssm.db02.dao.AccountMapper accountMapper;

	@Override
	public String goodIdea(com.whty.ssm.db02.pojo.Account from, com.whty.ssm.db02.pojo.Account to, float money) {
		if(null == from || null == to) return "账号不存在";
		if(from.getMoney() < money) return "账号余额不足";
		from.setMoney(from.getMoney()-money);
		to.setMoney(to.getMoney()+money);
		try{
			accountMapper.updateMoneyByIdName(from);
			accountMapper.updateMoneyByIdName(to);
			return "交易成功";
		}catch (Exception e){
			e.printStackTrace();
		}
		return "交易失败";
	}
}